package com.ruoyi.yljf.controller.AuthApiController;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.yljf.domain.Comment;
import com.ruoyi.yljf.domain.dto.CommentAddDTO;
import com.ruoyi.yljf.domain.enums.yljfEnums;
import com.ruoyi.yljf.domain.vo.CommentReplyListVO;
import com.ruoyi.yljf.service.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评论Controller
 *
 * @author metaee
 * @date 2025-02-14
 */
@RestController
@RequestMapping("api/comment")
public class ApiCommentController extends BaseController {

    @Autowired
    private ICommentService commentService;
    
    
    /**
     * 查询所有回复我的消息列表
     * @return
     */
    @GetMapping("/replyList")
    public TableDataInfo replyList(){
        startPage();
        //查询不是提问的回复
        List<Comment> list = commentService.selectCount(getUserId(),"question");
        List<CommentReplyListVO> result =  commentService.replyList( list);
        return getDataTableInfo(result,list);
    }

    /**
     * 查询我的提问列表
     * @return
     */
    @GetMapping("/myAsk")
    public TableDataInfo myAsk( ){
        startPage();
        List<Comment> list = commentService.selectQuestionCount(getUserId(),"question");
        List<CommentReplyListVO> listVO = commentService.queryAsk( list);
        return getDataTableInfo(listVO,list);
    }

    
    /**
     * 评论和提问新增
     */
    @PostMapping("/commentAdd")
    public AjaxResult commentAdd(@RequestBody CommentAddDTO request){

        Integer count = commentService.commentAdd(request);

        return AjaxResult.success(count);
    }


    /**
     * 疑难问师
     * @return
     */
    @PostMapping("/commentAddQuestion")
    public AjaxResult commentAddQuestion(@RequestBody CommentAddDTO comment){
        comment.setPostType(yljfEnums.QUESTION.getCode());
        return AjaxResult.success(commentService.commentAdd(comment));
    }

    


}
